﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LMS.SMSH.MODEL;
using LMS.SMSH.BLL;
using System.Data.Linq;
using System.Data;

namespace LMS.SMSH.WEB
{
    public partial class AdmMeassageView : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                #region 根据页面参数mesId，筛选出Message数据表的某条记录，并显示到界面，以便于管理员回复
                if (Request.QueryString["mesId"] != null)
                {
                    var query = LMSDataContext.GetLMSDB.TB_Message.Where(mes => mes.mesId == Int32.Parse(Request.QueryString["mesId"]));
                    TB_Message tb_message = query.ToArray().First();
                    txtCaption.Text = tb_message.mesTitle;
                    txtContent.Text = tb_message.mesDetail;
                    txtStudentID.Text = tb_message.mesStuNo;
                    txtReview.Text = tb_message.mesReply;
                }
                #endregion
            }
        }

        /// <summary>
        /// 将留言写入Message数据表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnOK_Click(object sender, EventArgs e)
        {
            #region 管理员根据页面参数mesId，将回复信息写入Message数据表
            if (Request.QueryString["mesId"] != null && Session["adminID"] != null)
            {
                TB_Message tb_message = LMSDataContext.GetLMSDB.TB_Message.Single(id => id.mesId == Int32.Parse(Request.QueryString["mesId"]));
                tb_message.mesAdminId = Session["adminID"].ToString();
                tb_message.mesReply = txtReview.Text.Trim();
                tb_message.mesStatus = "已处理";
                LMSDataContext.GetLMSDB.SubmitChanges();
                this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('留言回复成功!');window.location.href='AdmMessageManage.aspx';", true);
            }
            #endregion
        }



    }
}